<?php

namespace IDock\Printer\NonCar;

use IDock\Printer\BasePrinter;

/**
 * 非车产品单例
 */
class NonCarProductPrinter extends BasePrinter
{

    /**
     * 大类代码-产品名称代码
     * @var string $productCode
     */
    public $productCode = '';

    /**
     * 大类名称-产品名称
     * @var string $productName
     */
    public $productName = '';

    /**
     * 大类类型-产品类型 如 驾意险，财产险
     * @var string $productType
     */
    public $productType = '';

    /**
     * 产品描述
     * @var string $productDesc
     */
    public $productDesc = '';

    /**
     * 小类代码-方案编码
     * @var string $planCode
     */
    public $planCode = '';

    /**
     * 小类名称-方案名称
     * @var string $planName
     */
    public $planName = '';

    /**
     * 显示折扣
     * @var string $discount
     */
    public $discount = '';

    /**
     * 最大份数
     * @var int $maxQuantity
     */
    public $maxQuantity = 1;

    /**
     * 保额
     * @var int $unitAmount
     */
    public $unitAmount = '';

    /**
     * 保费
     * @var string $premium
     */
    public $premium = '';

    /**
     * 投保份数
     * @var string $insuredNum
     */
    public $insuredNum = '1';

    /**
     * 子险种列表
     * @var array $subCoverage
     */
    public $subCoverage = [];

    /**
     * argc
     * @var array $argc
     */
    public $argc = [];

    public function subCoverageAppend(NonCarSubCoveragePrinter $printer)
    {
        $this->subCoverage[] = $printer;
    }

    public function toArray(): array
    {
        $objectVars = get_object_vars($this);

        foreach ($objectVars as &$objectVar) {
            if (is_object($objectVar) and ($objectVar instanceof BasePrinter)) {
                $objectVar = $objectVar->toArray();
            }
            if (is_array($objectVar)) {
                foreach ($objectVar as &$item) {
                    if (is_object($item) and ($item instanceof BasePrinter)) {
                        $item = $item->toArray();
                    }
                }
            }
        }
        return $objectVars;
    }
}
